<!-- dolaczenie jQuery -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<!-- dolaczenie skryptu do template'owania danych -->
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

<!-- template do wyswietlenia wiadomosci json -->
<script id="feedTemplate" type="text/x-jquery-tmpl"> 
    <div class="feedItem">
        <h2>\${from.name}</h2>
        <h4>Napisano: \${created_time} Komentarzy: \${comments.count}</h4>
        <p class="message">\${message}</p>
        {{if story}}
            <p class="message">\${story}</p>
            {{if picture}}
                <img src="\${picture}" />
            {{/if}}
            <a href="\${link}">Link do tego elementu</a>
        {{/if}}
        {{if name}}
                <p class="adds">
                {{if picture}}
                    <img src="\${picture}" /> 
                {{/if}}
                Link:&nbsp;<a href="\${link}">\${name}</a><br />\${description}</p>
        {{/if}}
        {{if comments.count }}
        <hr />
        <strong>Komentarze:</strong><br />
        {{each comments.data}}
            \${from.name}: <em>\${message}. </em><br />
        {{/each}}
        {{/if}}
    </div>
</script>
<script id="feedTemplateError" type="text/x-jquery-tmpl"> 
    <div class="feedItem">
        <h2>\${message}</h2>
    </div>
</script>

<!-- pobranie i wyswietlenie danych w template'cie -->
<script type="text/javascript"> 
    jQuery.noConflict();   
    jQuery(document).ready(function($) {
        
        // funkcja wyswietlajaca wiadomosci
        function displayFeed(token) {
            //var fb_id = '100003695880436'
            
            var fb_id = 'me'
            var access_token = token;
            var requestURL='https://graph.facebook.com/'+fb_id+'/feed?access_token='+access_token+'&callback=?';

            $.getJSON(requestURL, function(json){
                var feedError = $( "#feedTemplateError" ).tmpl( json.error );
                $( "#feedError").html(feedError);
                var feed = $( "#feedTemplate" ).tmpl( json.data );
                $( "#feed").html(feed);
                $(".feedItem h2:not(:empty)").parent().addClass("visible");
                $(".feedItem:not(.visible)").fadeOut();
            });
        }
        
        $('#getFeed').live('click', function() {
            $("#feedError").empty();
            $("#feed").empty();
            displayFeed(localStorage.getItem("token"));
        });

    });
</script>